import urllib.request
import re
from datetime import datetime
import os


def save_link(dir_path):
    with urllib.request.urlopen("http://www.55188.com/viewthread.php?tid=5551406") as f:
        st = str(f.read())
    result = re.compile('http://pan.baidu.com/s/[^"<>]+').search(st)
    if result:
        link = result.group()
    date = datetime.today().strftime('%Y-%m-%d')
    with open(os.path.join(dir_path, 'links.csv'), 'a') as file:
        file.write(date + ' ' + link + '\n')
    file.close()

save_link = save_link
